/**
 * 
 */
package com.lvan.controller;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Stern He<br>
 *         2013-9-12<br>
 * @version 1.0.0.0
 */
public abstract class BaseController{
    protected HttpServletRequest request;
    public static final String SUCCESS = "success";
    public static final String INDEX = "main";
    public static final String ERROR = "error";
    public static final String FAILURE = "failure";
    public static final String DEFAULT = "defaultResult";

    public static final String LOGIN_FAIL = "登录失败";
    public String getIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("X-Cluster-Client-Ip");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }
    
}
